local lishou = fk.CreateSkill {
  name = "th_lishou",
  max_phase_use_time = 1,
  derived_piles = "$th_sekibanki_shou",
}

lishou:addEffect("active", {
  anim_type = "drawcard",
  prompt = "#th_lishou",
  min_card_num = 1,
  card_filter = function(self, player, to_select, selected, selected_targets)
    return Fk:currentRoom():getCardArea(to_select) == Card.PlayerHand
  end,
  target_num = 0,
  target_filter = Util.FalseFunc,
  on_use = function (self, room, effect)
    local player = effect.from
    local cards = effect.cards
    player:addToPile("$th_sekibanki_shou", cards, false, lishou.name)
  end
}, { check_skill_limit = true})
lishou:addEffect(fk.EnterDying, {
  anim_type = "drawcard",
  is_delay_effect = true,
  can_trigger = function(self, event, target, player, data)
    return target == player and #player:getPile("$th_sekibanki_shou") > 0
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:obtainCard(player, player:getPile("$th_sekibanki_shou"), false, fk.ReasonJustMove, player, lishou.name)
  end
})
lishou:addEffect(fk.TurnEnd, {
  anim_type = "drawcard",
  is_delay_effect = true,
  can_trigger = function(self, event, target, player, data)
    if not player:hasSkill(lishou.name) then return false end
    return #player:getPile("$th_sekibanki_shou") > 0
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if #player.room.logic:getActualDamageEvents(1, function (e)
      return e.data.to == player
    end, Player.HistoryTurn) > 0 then
      local cards = room:askToCards(player, {
        min_num = 1,
        max_num = 2,
        include_equip = false,
        skill_name =  lishou.name,
        cancelable = true,
        pattern = ".|.|.|$th_sekibanki_shou|.|.|.",
        prompt = "#th_lishou-obtain",
        expand_pile = "$th_sekibanki_shou"
      })
      room:obtainCard(player, cards, false, fk.ReasonPrey, player, lishou.name)
    else
      local cards = room:askToCards(player, {
        min_num = 1,
        max_num = 1,
        include_equip = false,
        skill_name =  lishou.name,
        cancelable = true,
        pattern = ".|.|.|$th_sekibanki_shou|.|.|.",
        prompt = "#th_lishou-invoke",
        expand_pile = "$th_sekibanki_shou"
      })
      room:moveCardTo(cards, Card.DiscardPile, nil, fk.ReasonPutIntoDiscardPile, lishou.name, nil, true, player)
      player:drawCards(2, lishou.name)
    end
  end
})

Fk:loadTranslationTable{
  ["th_lishou"] = "离首",
  [":th_lishou"] = "出牌阶段限一次，你可以将任意张手牌扣置于武将牌上，称为“首”，当你进入濒死状态时获得所有“首”。每回合结束时，若你本回合受到过伤害，你可以获得至多两张“首”，否则你须移去一张“首”并摸两张牌。",

  ["#th_lishou"] = "离首：将任意张手牌扣置于武将牌上，称为“首”",
  ["#th_lishou-use"] = "离首：你可以使用一张“首”",
  ["#th_lishou-invoke"] = "离首：你须移去一张“首”并摸两张牌",
  ["#th_lishou-obtain"] = "离首：你可以获得至多两张“首”",

  ["$th_sekibanki_shou"] = "首",
}

return lishou